package cc.admin.modules.sys.service.impl;

import cc.admin.common.exception.CcAdminException;
import cc.admin.modules.sys.entity.SysUploadTemplate;
import cc.admin.modules.sys.mapper.SysUploadTemplateMapper;
import cc.admin.modules.sys.service.ISysUploadTemplateService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * Sys upload template service
 *
 * @author 赵森涛
 * @date 2022.10.31 11:26:50
 * @description description
 */
@Service
public class SysUploadTemplateServiceImpl extends ServiceImpl<SysUploadTemplateMapper, SysUploadTemplate> implements ISysUploadTemplateService {

    @Autowired
    private SysUploadTemplateMapper uploadTemplateMapper;

    @Override
    public SysUploadTemplate queryTemplate(String busKey, Integer type) {
        QueryWrapper<SysUploadTemplate> queryWrapper = new QueryWrapper();
        queryWrapper.eq("type", type)
                .eq("bus_key", busKey);
        List<SysUploadTemplate> list = uploadTemplateMapper.selectList(queryWrapper);

        if (list.size() > 0) {
            return list.get(0);
        } else {
            throw new CcAdminException("未查询到模板，请联系管理员");
        }
    }

}
